﻿using System;
using System.Collections.Generic;

namespace DSAManager.Models.Output
{
    /// <summary>
    /// 订单信息
    /// </summary>
    public class OrderInfo
    {
        public OrderInfo()
        {
            details = new List<OrderDetail>();
        }

        public string no { get; set; }
        public string wangwang { get; set; }
        public int num { get; set; }
        public DateTime time { get; set; }
        public List<OrderDetail> details { get; set; }
        public bool hasdownload { get; set; }
        public int uploadnum
        {
            get
            {
                int d = 0;
                foreach (var detail in details)
                {
                    foreach (var img in detail.images)
                    {
                        d += img.num;
                    }
                }
                return d;
            }
        }
        public DateTime? downloadtime { get; set; }
        public bool hassend { get; set; }
        public DateTime? sendtime { get; set; }
        public string printwangwang { get; set; }
        public int source { get; set; }
        public int realnum
        {
            get
            {
                int d = 0;
                foreach (var detail in details)
                {
                    d += detail.num;
                }
                return d;
            }
        }

        public string getSavePath()
        {
            string path = "";
            foreach (var detail in details)
            {
                if (!string.IsNullOrEmpty(path))
                    path += "、";
                path += detail.pathName;
            }
            path = path + "+" + wangwang + "+" + no;

            return path;
        }

        public void ReBuilderDetail()
        {
            //合并过的尺寸，合并在一起
            foreach (var detail in details)
            {
                if (detail.isJoin) continue;
                if (detail.isdel) continue;

                for (int i = details.Count - 1; i >= 0; i--)
                {
                    var orderDetail = details[i];
                    if (!orderDetail.isJoin) break;
                    if (detail.isdel) continue;
                    if (detail.printSize == orderDetail.printSize && detail.paper == orderDetail.paper)
                    {
                        detail.images.AddRange(orderDetail.images);
                        orderDetail.isdel = true;
                    }
                }
            }
        }
    }

    public class OrderDetail
    {
        public OrderDetail()
        {
            images = new List<OrderImage>();
        }

        internal bool isdel { get; set; }
        public string no { get; set; }
        public string name { get; set; }
        public string size { get; set; }
        public string type { get; set; }
        public string paper { get; set; }
        public string packagetype { get; set; }
        /// <summary>
        /// 上传通道
        /// </summary>
        public int uploadtype { get; set; }
        public int num { get; set; }
        public List<OrderImage> images { get; set; }
        public string parperAlias
        {
            get
            {
                switch (paper)
                {
                    case "富士晶彩绒面": return "富士绒面";
                    case "富士晶彩光面": return "富士光面";
                    case "柯达晶彩绒面": return "柯达绒面";
                    case "柯达晶彩光面": return "柯达光面";
                    case "柯达金尊光面": return "柯达金尊";
                    default: return paper;
                }
            }
        }

        public bool isJoin { get { return size != printSize; } }//是否合并
        public string printSize
        {
            get
            {
                if (size == "3寸") return "5寸";
                if (size == "4寸") return "6寸";
                return size;
            }
        }

        public string pathName
        {
            get
            {
                string name = "";
                string size_alias = size;
                if (size_alias == "3寸") size_alias = "5寸";
                if (size_alias == "4寸") size_alias = "6寸";
                size_alias = size_alias.Replace("寸", "");
                name += size_alias;

                switch (paper)
                {
                    case "富士晶彩绒面":
                        name += "F绒";
                        break;
                    case "富士晶彩光面":
                        name += "F光";
                        break;
                    case "柯达晶彩绒面":
                        name += "K绒";
                        break;
                    case "柯达晶彩光面":
                        name += "k光";
                        break;
                    case "柯达金尊光面":
                        name += "k金";
                        break;
                }
                if (packagetype == "过塑")
                    name += "塑";
                if (packagetype == "冷裱")
                    name += "冷";

                return name;
            }
        }

        internal string savepath { get; set; }

        /// <summary>
        /// 判断该规格的图片是否都是打印1份的
        /// </summary>
        /// <returns></returns>
        public bool checkAllIsSigle()
        {
            foreach (var image in images)
            {
                if (image.num > 1) return false;
            }
            return true;
        }
    }

    public class OrderImage
    {
        //public string imageurl { get; set; }
        //public int num { get; set; }
        //public string rotateangle { get; set; }
        //public string Height { get; set; }
        //public string Width { get; set; }
        //public string X { get; set; }
        //public string Y { get; set; }
        /// <summary>
        /// 卖家裁剪
        /// </summary>
        public bool sellerCut { get; set; }
        private bool _IsCut = true;
        /// <summary>
        /// 客户是否裁剪
        /// </summary>
        public bool IsCut
        {
            get { return _IsCut; }
            set { _IsCut = value; }
        }
        public int tubW { get; set; }
        public int tubH { get; set; }
        /// <summary>
        /// 微信图片地址
        /// </summary>
        public string serverid { get; set; }
        /// <summary>
        /// 图片地址
        /// </summary>
        public string url { get; set; }
        /// <summary>
        /// 图片真实宽度
        /// </summary>
        public int Width { get; set; }
        /// <summary>
        /// 图片真实高度
        /// </summary>
        public int Height { get; set; }

        /// <summary>
        /// 显示宽度
        /// </summary>
        public decimal WidgetWidth { get; set; }
        /// <summary>
        /// 显示高度
        /// </summary>
        public decimal WidgetHeight { get; set; }
        /// <summary>
        /// 起始X
        /// </summary>
        public decimal BeginX { get; set; }
        /// <summary>
        /// 起始Y
        /// </summary>
        public decimal BeginY { get; set; }
        /// <summary>
        /// 结束X
        /// </summary>
        public decimal EndX { get; set; }
        /// <summary>
        /// 结束Y
        /// </summary>
        public decimal EndY { get; set; }

        /// <summary>
        /// 旋转角度
        /// </summary>
        public int rotateangle { get; set; }
        /// <summary>
        /// X坐标
        /// </summary>
        public int X { get; set; }
        /// <summary>
        /// Y坐标
        /// </summary>
        public int Y { get; set; }
        /// <summary>
        /// 裁剪宽度
        /// </summary>
        public int CutW { get; set; }
        /// <summary>
        /// 裁剪高度
        /// </summary>
        public int CutH { get; set; }
        private int _num = 1;
        /// <summary>
        /// 图片数量
        /// </summary>
        public int num
        {
            get { return _num; }
            set { _num = value; }
        }
        internal string savepath { get; set; }
    }
}